package Operation;

import Book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList booklist) {
        int choic = 1;
        Scanner scanner = new Scanner(System.in);
        while(choic==1) {
            System.out.println("请输入你要删除书的名字》");
            String name = scanner.nextLine();
            int tail = 0;
            int i = 0;
            for (i = 0; i < booklist.getUsedSize(); i++) {
                if (name.equals(booklist.getName(i))) {
                    tail = i;
                    break;
                }
            }
            if (i == booklist.getUsedSize()) {
                System.out.println("找不到这本书，无法删除！");
            } else {
                for (int j = tail; j < booklist.getUsedSize() - 1; j++) {
                    booklist.setBook(booklist.getBook(j + 1), j);
                }
                booklist.setUsedSize(booklist.getUsedSize()-1);
                System.out.println("找到了，已删除！");
            }
            System.out.println("是否继续添加》  1》继续   0》停止  输入其他数字》停止");
            choic = scanner.nextInt();
        }
    }
}
